package model;

import static org.junit.Assert.*;

import java.util.GregorianCalendar;

import org.junit.Before;
import org.junit.Test;

public class PNTest {

	PN prescription;

	@Before
	public void setUp() throws Exception {
	}

	@Test
	public void testTotalDose() {
		prescription = new PN(new GregorianCalendar(2008, 1, 1),
				new GregorianCalendar(2008, 2, 1), 1);
		assertEquals(0, prescription.totalDose());

		prescription.addDose(new GregorianCalendar(2008, 1, 19));
		assertEquals(1, prescription.totalDose());

		prescription.addDose(new GregorianCalendar(2008, 1, 29));
		assertEquals(2, prescription.totalDose());

		prescription.addDose(new GregorianCalendar(2008, 1, 13));
		prescription.addDose(new GregorianCalendar(2008, 1, 05));
		assertEquals(4, prescription.totalDose());

		prescription.addDose(new GregorianCalendar(2008, 1, 27));
		prescription.addDose(new GregorianCalendar(2008, 1, 29));
		prescription.addDose(new GregorianCalendar(2008, 1, 24));
		prescription.addDose(new GregorianCalendar());
		assertEquals(8, prescription.totalDose());

		prescription = new PN(new GregorianCalendar(2008, 2, 1),
				new GregorianCalendar(2008, 2, 1), 10);
		assertEquals(0, prescription.totalDose());

		prescription.addDose(new GregorianCalendar(2008, 1, 19));
		assertEquals(10, prescription.totalDose());

		prescription.addDose(new GregorianCalendar(2008, 1, 29));
		assertEquals(20, prescription.totalDose());

		prescription.addDose(new GregorianCalendar(2008, 1, 13));
		prescription.addDose(new GregorianCalendar(2008, 1, 05));
		assertEquals(40, prescription.totalDose());

		prescription.addDose(new GregorianCalendar(2008, 1, 27));
		prescription.addDose(new GregorianCalendar(2008, 1, 29));
		prescription.addDose(new GregorianCalendar(2008, 1, 24));
		prescription.addDose(new GregorianCalendar());
		assertEquals(80, prescription.totalDose());
	}

	@Test
	public void testDayDose() {	
		// Testing 1 day
		prescription = new PN(new GregorianCalendar(2008, 2, 1),
				new GregorianCalendar(2008, 2, 1), 1);
		assertEquals(0, prescription.dayDose());

		// Testing 1 day
		prescription.addDose(new GregorianCalendar(2008, 2, 1));
		assertEquals(1, prescription.dayDose());

		// Testing 1 day
		prescription = new PN(new GregorianCalendar(2008, 2, 1),
				new GregorianCalendar(2008, 2, 1), 10);
		prescription.addDose(new GregorianCalendar(2008, 2, 1));
		assertEquals(10, prescription.dayDose());

		// Testing 1 day
		prescription = new PN(new GregorianCalendar(2008, 2, 1),
				new GregorianCalendar(2008, 2, 1), 50);
		prescription.addDose(new GregorianCalendar(2008, 2, 1));
		assertEquals(50, prescription.dayDose());

		// Testing 1 day
		prescription = new PN(new GregorianCalendar(2008, 2, 1),
				new GregorianCalendar(2008, 2, 1), 100);
		prescription.addDose(new GregorianCalendar(2008, 2, 1));
		assertEquals(100, prescription.dayDose());

		// ....
		
		// Testing 5 days
		prescription = new PN(new GregorianCalendar(2008, 2, 1),
				new GregorianCalendar(2008, 2, 5), 1);
		assertEquals(0, prescription.dayDose());

		// Testing 5 days
		prescription.addDose(new GregorianCalendar(2008, 2, 1));
		assertEquals(0.2, prescription.dayDose());

		// Testing 5 days
		prescription = new PN(new GregorianCalendar(2008, 2, 1),
				new GregorianCalendar(2008, 2, 5), 10);
		prescription.addDose(new GregorianCalendar(2008, 2, 1));
		assertEquals(2, prescription.dayDose());

		// Testing 5 days
		prescription = new PN(new GregorianCalendar(2008, 2, 1),
				new GregorianCalendar(2008, 2, 5), 50);
		prescription.addDose(new GregorianCalendar(2008, 2, 1));
		assertEquals(10, prescription.dayDose());

		// Testing 5 days
		prescription = new PN(new GregorianCalendar(2008, 2, 1),
				new GregorianCalendar(2008, 2, 5), 100);
		prescription.addDose(new GregorianCalendar(2008, 2, 1));
		assertEquals(20, prescription.dayDose());

		// .....
		
		// Testing 36 days
		prescription = new PN(new GregorianCalendar(2008, 2, 1),
				new GregorianCalendar(2008, 3, 5), 1);
		assertEquals(0, prescription.dayDose());

		// Testing 36 days
		prescription.addDose(new GregorianCalendar(2008, 2, 1));
		assertEquals(0.3, prescription.dayDose());

		// Testing 36 days
		prescription = new PN(new GregorianCalendar(2008, 2, 1),
				new GregorianCalendar(2008, 3, 5), 10);
		prescription.addDose(new GregorianCalendar(2008, 2, 1));
		assertEquals(0.28, prescription.dayDose());

		// Testing 36 days
		prescription = new PN(new GregorianCalendar(2008, 2, 1),
				new GregorianCalendar(2008, 3, 5), 50);
		prescription.addDose(new GregorianCalendar(2008, 2, 1));
		assertEquals(1.39, prescription.dayDose());

		// Testing 36 days
		prescription = new PN(new GregorianCalendar(2008, 2, 1),
				new GregorianCalendar(2008, 3, 5), 100);
		prescription.addDose(new GregorianCalendar(2008, 2, 1));
		assertEquals(2.78, prescription.dayDose());
	}
	
	@Test
	public void testDoseGiven() {		
		prescription = new PN(new GregorianCalendar(2008, 2, 1),
				new GregorianCalendar(2008, 2, 1), 1);
		assertFalse(prescription.doseGiven(new GregorianCalendar(2008, 2, 1)));

		prescription.addDose(new GregorianCalendar(2008, 2, 1));
		assertTrue(prescription.doseGiven(new GregorianCalendar(2008, 2, 1)));

		prescription.addDose(new GregorianCalendar(2008, 2, 1));
		assertTrue(prescription.doseGiven(new GregorianCalendar(2008, 2, 1)));

		prescription = new PN(new GregorianCalendar(2008, 2, 1),
				new GregorianCalendar(2008, 2, 2), 1);
		prescription.addDose(new GregorianCalendar(2008, 2, 1));
		prescription.addDose(new GregorianCalendar(2008, 2, 2));
		assertTrue(prescription.doseGiven(new GregorianCalendar(2008, 2, 2)));

		assertFalse(prescription.doseGiven(new GregorianCalendar(2008, 1, 3)));

		prescription = new PN(new GregorianCalendar(2008, 2, 1),
				new GregorianCalendar(2008, 3, 1), 1);
		prescription.addDose(new GregorianCalendar(2008, 2, 1));
		prescription.addDose(new GregorianCalendar(2008, 2, 2));
		prescription.addDose(new GregorianCalendar(2008, 2, 20));
		prescription.addDose(new GregorianCalendar(2008, 2, 26));
		assertFalse(prescription.doseGiven(new GregorianCalendar(2008, 2, 25)));

		prescription.addDose(new GregorianCalendar(2008, 2, 27));
		assertTrue(prescription.doseGiven(new GregorianCalendar(2008, 2, 26)));
	}
	
	public void testgetNumberOfTimesGiven() {
		prescription = new PN(new GregorianCalendar(2008, 2, 1),
				new GregorianCalendar(2008, 2, 1), 1);
		prescription.addDose(new GregorianCalendar(2008, 2, 1));
		prescription.addDose(new GregorianCalendar(2008, 2, 1));
		assertEquals(2, prescription.getNumberOfTimesGiven());
		
		prescription = new PN(new GregorianCalendar(2008, 2, 1),
				new GregorianCalendar(2008, 2, 2), 1);
		prescription.addDose(new GregorianCalendar(2008, 2, 1));
		prescription.addDose(new GregorianCalendar(2008, 2, 2));
		assertEquals(2, prescription.getNumberOfTimesGiven());
		
		prescription = new PN(new GregorianCalendar(2008, 2, 1),
				new GregorianCalendar(2008, 2, 1), 1);
		prescription.addDose(new GregorianCalendar(2008, 2, 1));
		prescription.addDose(new GregorianCalendar(2008, 2, 1));
		prescription.addDose(new GregorianCalendar(2008, 2, 2));
		assertEquals(3, prescription.getNumberOfTimesGiven());
		
		prescription = new PN(new GregorianCalendar(2008, 2, 1),
				new GregorianCalendar(2008, 2, 2), 1);
		prescription.addDose(new GregorianCalendar(2008, 2, 1));
		prescription.addDose(new GregorianCalendar(2008, 2, 2));
		prescription.addDose(new GregorianCalendar(2008, 2, 20));
		prescription.addDose(new GregorianCalendar(2008, 2, 26));
		assertEquals(4, prescription.getNumberOfTimesGiven());
		
		prescription = new PN(new GregorianCalendar(2008, 2, 1),
				new GregorianCalendar(2008, 2, 2), 1);
		prescription.addDose(new GregorianCalendar(2008, 2, 1));
		prescription.addDose(new GregorianCalendar(2008, 2, 2));
		prescription.addDose(new GregorianCalendar(2008, 2, 20));
		prescription.addDose(new GregorianCalendar(2008, 2, 25));
		prescription.addDose(new GregorianCalendar(2008, 2, 27));
		assertEquals(5, prescription.getNumberOfTimesGiven());
	}
}
